package s2elinshu;

import java.util.Scanner;

public class J15Ch05Calculator {
	// 공통 : a,b 값
	public static void main(String[] args) {
		J15Ch05Calculator0 c  = null;

		Scanner sc = new Scanner(System.in);
		System.out.println("a값 입력");
		int a = sc.nextInt();
		System.out.println("연산자 입력");
		String ba = sc.next();
		System.out.println("b값 입력");
		int b = sc.nextInt();

		if(ba.equals("+")){
			c = new J15Ch05CalculatorAdd();
			c.setValue(a, b);
			c.print();
		}
		else if(ba.equals("-")){
			c = new J15Ch05CalculatorSub(); 
			c.setValue(a, b);
			c.print();
		}
		else if(ba.equals("*")){
			c = new J15Ch05CalculatorMul();
			c.setValue(a, b);
			c.print();
		}
		else {
			c = new J15Ch05CalculatorDiv();
			c.setValue(a, b);
			c.print(); 
		}
		sc.close();
}
	
    /* switch (ba) {
		case "+":
			ca = new J15Ch05CalculatorAdd();
			ca.setValue(a, b);
			ca.print();
			break;
		case "-":
			cs = new J15Ch05CalculatorSub(); 
			cs.setValue(a, b);
			cs.print();
			break;
		case "*":
			cm = new J15Ch05CalculatorMul();
			cm.setValue(a, b);
			cm.print();
			break;
		case "/":
			cd = new J15Ch05CalculatorDiv();
			cd.setValue(a, b);
			cd.print();
			break;
		default:
			System.out.println("잘못된 입력값입니다.");
		} // switch 문의 경우 문자를 검색할 수 있다 단, if는 잘 안 됨.
		sc.close();
	}*/

	} // J15Ch05Calculator class 닫음	
	class J15Ch05Calculator0{
	private int a;
	private int b;

	public void setValue(int a, int b) {this.a=a;this.b =b;}
	public int getA() {	return a;}
	public int getB() {	return b;}

	public void print(){
		System.out.println(a);
		System.out.println(b);
	}

	}//J15Ch05Calculator
class J15Ch05CalculatorAdd extends  J15Ch05Calculator0 {	
	public int getAdd() {return (getA() + getB() );}
	@Override
	public void print(){
		System.out.println(getAdd() );
	}
} // J15Ch05CalculatorAdd

class J15Ch05CalculatorSub extends J15Ch05Calculator0 {
	public int getSub() {return (getA() - getB() );}
	@Override
	public void print(){
		System.out.println(getSub() );
	}
} // J15Ch05CalculatorSub

class J15Ch05CalculatorMul extends J15Ch05Calculator0 {	
	public int getMul() {return (getA() * getB() );}
	@Override
	public void print(){
		System.out.println(getMul() );
	}
}// J15Ch05CalculatorMul

class J15Ch05CalculatorDiv extends J15Ch05Calculator0 {
	public int getDiv() {return (getA() / getB() );}
	@Override
	public void print(){
		System.out.println(getDiv());
	}
} // J15Ch05CalculatorDiv

